package com.uzhie.jt808.msg.entity.JT_200;

import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.IPositionAdditionalItem;
import com.uzhie.jt808.msg.entity.MyBuffer;

import java.util.HashMap;
import java.util.Map;

/**
 * 1078 异常驾驶行为报警
 * Created by lilongfei on 2018/7/31.
 */
public class Media_Fatigue implements IPositionAdditionalItem {

    @Override
    public final int getAdditionalId()
    {
        return 0x18;
    }
    @Override
    public final byte getAdditionalLength()
    {
        return 0x04;
    }

    /* 信号报警相关
    *  bit1 疲劳 bit2 打电话  bit3 抽烟
    */
    private int type;

    /*
    疲劳程度
     */
    private byte level;

    private Map<Integer, Integer> status;

    public byte getLevel() {
        return level;
    }

    public void setLevel(byte level) {
        this.level = level;
    }

    public int getLevet(){
        return level;
    }


    public Map<Integer, Integer> getStatus() {
        return status;
    }

    public void setStatus(Map<Integer, Integer> status) {
        this.status = status;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public byte[] WriteToBytes() {
        return BitConverter.GetBytes(getType());
    }

    @Override
    public void ReadFromBytes(byte[] body) {
        MyBuffer buffer = new MyBuffer(body);
        setType(BitConverter.ToUInt16(buffer.gets(2),0));
        setLevel(buffer.get());
        status = new HashMap<>();
        for (int i=0  ;i<3;i ++){
            byte t = (byte) ((getType() >> (i)) & 0x0001);
            if (t == 1) status.put(i, (int) t);
//            System.out.println("当前存储位:" + i + ", 设备状态 : " + (t==0 ? "正常":"丢失"));
        }
    }
}
